package LeetCode;

public class Code287_findDuplicate {

    public int findDuplicate(int[] nums) {
        if (nums == null || nums.length == 0){
            return 0;
        }
        int slow = 0;
        int fast = 0;
        do {
            slow = nums[slow];
            fast = nums[nums[fast]];
        } while (slow != fast);
        slow = 0;
        while (slow != fast){
            slow = nums[slow];
            fast = nums[fast];
        }
        return slow;
    }
}
